package com.hejing.面向对象特征之二_继承.this关键字;

/**
 * ClassName: Boy
 * Package: com.hejing.this关键字
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-03-25 10:01
 * @Version: 1.0
 */
public class Boy {
    private String name;
    private int age;

    // 构造器:
    public Boy() {
        System.out.println("Boy无参构造器的调用");
    }

    public Boy(String name) {
        this();
        this.name = name;
    }

    public Boy(String name, int age) {
        this(name);
        this.age = age;
    }

    // 方法:

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void marry(Girl girl) {
        System.out.println("与" + girl.getName() + "女士结为夫妻");
    }

    public void shout() {
        if(this.age >= 22) {
            System.out.println("我终于可以结婚了");
        } else{
            System.out.println("我只能谈恋爱");
        }
    }
}

































